﻿@model IEnumerable<vngoodlife.MenuList>


@if (ViewBag.textTargetID != "")
{
<select id="@ViewBag.id" name="@ViewBag.id" textTargetID="@ViewBag.textTargetID" valueTargetID="@ViewBag.valueTargetID">
        <option value=""> -Chọn- </option>
    @foreach (var item in Model.Where(u => u.Superior == 0))
    {
        @Html.Raw("<optgroup label=\"" + item.MenuName + "\">")
   foreach (var sub in Model.Where(u => u.Superior == item.MenuListID))
   { 
            <option value="@sub.MenuListID">@sub.MenuName</option>
   }
        @Html.Raw("</optgroup>")
    }
</select>
}
else
{
<select id="@ViewBag.id" name="@ViewBag.id" onchange = "this.form.submit();">
        <option value=""> -Tất cả- </option>
    @foreach (var item in Model.Where(u => u.Superior == 0))
    {
        @Html.Raw("<optgroup label=\"" + item.MenuName + "\">")
        foreach (var sub in Model.Where(u => u.MenuListID == item.MenuListID || u.Superior == item.MenuListID))
   {
       if (sub.MenuListID != ViewBag.CurrentArticleTypeID)
       {
            <option value="@sub.MenuListID">@sub.MenuName</option>
       }
       else
       {
            <option selected="selected" value="@sub.MenuListID">@sub.MenuName</option>
       }
   }
        @Html.Raw("</optgroup>")
    }
</select>
}